class Person {
    //通过constructor定义的时候给 this.xxxx 赋值，就相当于有这个属性
    // name;
    // age;
    constructor(name, age = 19) {
        this.name = name
        this.age = age
    }


    sayHi() {
        console.log(`我是${this.name},今年 :${this.age}`);
    }

    get age() {
        return this._age;
    }

    set age(value) {
        if (typeof value === 'number') {
            this._age = value
        } else {
            console.log("异常数据，恢复默认值");

            this._age = 0
        }

    }


}

let p1 = new Person("张飞", 50);
// console.log("p1", p1);

p1.age = "sadfsaf"

p1.sayHi()
